package com.leejxx.health.service.impl;

import com.leejxx.health.dao.OrderSettingDao;
import com.leejxx.health.pojo.OrderSetting;
import com.leejxx.health.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author LeeJx
 * @ClassName OrderSettingServiceImpl
 * @Description TODO
 * @date 2021/1/3 21:34
 * @Version 1.0
 */
@DubboService
@Slf4j
public class OrderSettingServiceImpl implements OrderSettingService {
    @Autowired
    private OrderSettingDao orderSettingDao;

    @Override
    @Transactional
    public void addAll(List<OrderSetting> list) {
        //如果存在已有日期更新信息
        for (OrderSetting orderSetting : list) {
            OrderSetting orderFind = orderSettingDao.findByDate(orderSetting.getOrderDate());
            if (null == orderFind) {
                orderSettingDao.add(orderSetting);
            } else {
                orderSettingDao.update(orderSetting);
            }
        }
    }

    @Override
    public List<OrderSetting> findOrderSetting(String year, String month) {
        if (Integer.parseInt(month) < 10) {
            month = 0 + month;
        }
        String date = year + "-" + month;
        return orderSettingDao.findOrderSetting(date);
    }

    @Override
    public void editNumber(String orderDate, String number) {
        orderSettingDao.editNumber(orderDate, number);
    }
}
